# -*- coding: utf8 -*-
from pyramid_layout.panel import panel_config
from pyramid.security import authenticated_userid

from .models import get_eleve_info
from .security import groupfinder


@panel_config(name='dropdown_menu_panel',
              renderer='templates/panels/dropdown_menu_panel.pt')
def dropdown_menu_panel(context, request):
    logged_in = authenticated_userid(request)

    if logged_in is None:
        return { 'logged_in': '' }
    elif logged_in == u'000000':
        fullname = u"Administrateur"
        email = request.registry.settings['monaem.admin_email']
        permis = ""
    else:
        member_info = get_eleve_info(logged_in)
        fullname = member_info['fullname']
        email = member_info['email']
        permis = member_info['permis']

    groups = groupfinder(logged_in, request)
    if 'group:administrators' in groups:
        is_admin = True
    else:
        is_admin = False

    return {
        'logged_in': logged_in,
        'logged_in_name': fullname,
        'logged_in_email': email,
        'logged_in_permis': permis,
        'is_admin': is_admin,
        }



